<?php

class Application_Model_RelatorioDespesa extends Zend_Db_Table_Abstract {

    protected $_name = 'relatorio';
    protected $_primary = 'codigo';
    private static $instance;

    public static function getInstance() {
        if (!isset(self::$instance)) {
            self::$instance = new Application_Model_RelatorioDespesa();
            return self::$instance;
        }
        return self::$instance;
    }

    public function lista($data) {

        $sql = 'select d.codigo,d.descricao,d.dt_cadastro,d.valor,d.dt_vencimento,d.dt_pagamento, valor
                from despesa d
                
                where d.dt_exclusao is null ';

        if(isset($data['descricao']) && !empty($data['descricao'])){
            $sql.=' and d.descricao like \''. $data['descricao']. '%\'';
        }

        if(isset($data['dt_cadastro']) && !empty($data['dt_cadastro'])){
            $sql.=' and d.dt_cadastro = \''. Util_Function_Util::formataData($data['dt_cadastro'], 'Y/M/d'). '\'';
        }

        if(isset($data['dt_vencimento']) && !empty($data['dt_vencimento'])){
            $sql.=' and d.dt_vencimento = \''. Util_Function_Util::formataData($data['dt_vencimento'], 'Y/M/d'). '\'';
        }

        if(isset($data['dt_pagamento']) && !empty($data['dt_pagamento'])){
            $sql.=' and d.dt_pagamento = \''. Util_Function_Util::formataData($data['dt_pagamento'], 'Y/M/d'). '\'';
        }

        /*if(isset($data['tipo_despesa']) && !empty($data['tipo_despesa'])){
            $sql.=' and tp.descricao = \''. $data['tipo_despesa'].'\'';
        }*/

        /*if (isset($orderName) && isset($order)) {
            $sql .= ' order by d.' . $orderName . ' ' . $order;
        }*/

        $rs = $this->getAdapter()->query($sql)->fetchAll();

        return $rs;
    }

    
}